<?php
include 'utilities.php';
include 'crawl.php';
Utititles::includeClasses();

$crawl = new Crawl();
$sc_tours = Sources::$tournaments;
$tb_tournaments = new Tb_Tournaments();

// Crawl
foreach ($sc_tours as $sc_tour) {
    $tournaments = NULL;
    $url = $sc_tour['url'];
    $content = $crawl->getPage($url);
    $matches =$crawl->parseData($content, $sc_tour['pattern']);
    if (!empty($matches[1])) {
        $index = 0;
        foreach ($matches[1] as $url_club) {
            $tournaments[] = array(
                'name'  =>  $matches[2][$index],
                'source' => $sc_tour['source'],
                'url_club' => $url_club
            );
            $index++;
        }
        $tb_tournaments->insert($tournaments);
    }
}